package com.atguigu.gmall.item.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.service.SkuDetailService;
import com.atguigu.gmall.product.vo.SkuDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/inner/rpc/item")
public class SkuDetailRpcController {

    @Autowired
    SkuDetailService skuDetailService;

    @GetMapping("/sku/detail/{skuId}")
    public Result<SkuDetailVo> getSkuDetails(@PathVariable Long skuId){
        // 1.切面拦截：如果缓存中有，真正方法都不一样。
        SkuDetailVo skuDetailData = skuDetailService.getSkuDetailData(skuId);

        // 2.增加商品热度
        skuDetailService.incrHotScore(skuId);

        // 商品详情
        return Result.ok(skuDetailData);
    }
}
